<template>
    <div>
        <el-dialog top="5%" :title="title" size="large" v-model="NowFormVisible" :close-on-click-modal="false">
            <el-form  ref="form" :model="form" :inline="true" :rules="rules" label-width="150px">
            <el-form-item label="工程">
                <el-input disabled  v-model="form.FName" style="width:250px;"></el-input>
            </el-form-item>
                <el-form-item label="进度日期">
                    <el-date-picker type="date" disabled  v-model="NewDate" style="width:250px;"></el-date-picker>
                </el-form-item>
        </el-form>
            <div style="border: 1px solid #bbb; padding: 20px;">

            <el-table
                    :data="listdata"
                    border
                    v-loading="listLoading"
                    style="width: 100%">
                <el-table-column
                        prop="FSubitemName"
                        label="单项工程"
                        width="280">
                </el-table-column>
                <el-table-column
                        v-for="(item,index) in columnslist"
                        :prop="'FItem'+(index+1)"
                        :label="item.FName"
                        width="120">
                    <template scope="scope">
                        <span v-if="scope.row['FItem'+(index+1)+'old']<scope.row['FItem'+(index+1)+'new']" style="color:red">{{scope.row['FItem'+(index+1)+'new']}}</span>
                        <span v-else>{{scope.row['FItem'+(index+1)+'new']}}</span>
                        /
                        <span> {{scope.row['FItem'+(index+1)]}}</span>
                    </template>
                </el-table-column>
            </el-table>
            </div>
      </el-dialog>
    </div>
</template>

<script>
    import util from '../../common/util'
    import mixin from '../../common/mixin'
    import Vue from 'vue'
    export default {
        data() {
            return {
                form: {},
                showSave:true,
                rules: {
                   // FName: [{type: "date",name:"FCreateDate",text:"跟进时间", value: null}]
                },
                loading:false,
                NowFormVisible:false,
                title:'',
                listdata: [],
                listLoading:false,
                showcontent:true,
                fixWhere:'',
                columnslist:[],
                NewDate:''
            }
        },
        computed: {

        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record) {
                this.NowFormVisible = true;
                this.form = Object.assign({},record);
                this.title = '编辑'
                this.listdata=[]
                util.get("server/business/Single.ashx?cmd=GetList",
                    {where:"FProjectID="+this.form.FID,start:"0",limit:'10'},this.switchLoading,result=>{
                        this.columnslist = result.data
                    })
                util.get("server/business/ScheduleTarget.ashx?cmd=GetList",
                    {where:"FProjectID="+this.form.FID},this.switchLoading,result=>{
                       if(result.listdata.length!=0) {
                          this.listdata = result.listdata
                           if(result.listdata[0].FNewDate!='/Date(-62135596800000)/'){
                           this.NewDate = util.date.parseToDate(result.listdata[0].FNewDate,'yyyy-MM-dd')
                          }else{
                               this.NewDate =''
                           }
                       }
                       else{
                           util.get("server/business/Subitem.ashx?cmd=GetList",
                               {where:"FProjectID="+this.form.FID,start:"0",limit:'100'},this.switchLoading,result=>{
                                  for(let pro of result.data)
                                  {
                                      this.listdata.push({FSubitemID:pro.FID,FProjectID:this.form.FID,FSubitemName:pro.FName,
                                          FItem1:'0',FItem2:'0',FItem3:'0',FItem4:'0',FItem5:'0',
                                          FItem6:'0',FItem7:'0',FItem8:'0',FItem9:'0',FItem10:'0',
                                          FItem1new:'0',FItem2new:'0',FItem3new:'0',FItem4new:'0',FItem5new:'0',
                                          FItem6new:'0',FItem7new:'0',FItem8new:'0',FItem9new:'0',FItem10new:'0',
                                          FItem1old:'0',FItem2old:'0',FItem3old:'0',FItem4old:'0',FItem5old:'0',
                                          FItem6old:'0',FItem7old:'0',FItem8old:'0',FItem9old:'0',FItem10old:'0'
                                          })
                                  }
                               })
                       }
                    })
            },
            save:function () {
                this.form.listdata = JSON.stringify(this.listdata);
                util.post("server/business/ScheduleTarget.ashx?cmd=Save",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc", this.form)

                })
            }
        },
        mounted() {

        }
    }
</script>
